package com.hxzy.controller.mobile.category;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hxzy.common.resp.R;
import com.hxzy.controller.mobile.category.resp.MobileCategoryResp;
import com.hxzy.controller.mobile.mapstruct.MobileCategoryConvert;
import com.hxzy.entity.CategoryClass;
import com.hxzy.service.CategoryClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author wy
 * @Description TODO
 * @Date 2023/9/27 15:07
 * @Version 1.0
 */
@Api(tags = "H5-商品分类")
@RestController
@RequestMapping(value = "/mobile/category")
public class MobileCategoryController {

    @Autowired
    private CategoryClassService categoryClassService;

    @ApiOperation(value = "商家分类")
    @GetMapping(value = "/list/{merchantId}")
    public R<List<MobileCategoryResp>> searchByMerchantId(@PathVariable(value = "merchantId") Long merchantId){
        LambdaQueryWrapper<CategoryClass> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(CategoryClass::getMerchantId, merchantId);
        queryWrapper.select(CategoryClass::getId,CategoryClass::getName,CategoryClass::getPicture);
        queryWrapper.orderByAsc(CategoryClass::getCreateTime);

        List<CategoryClass> list = this.categoryClassService.list(queryWrapper);

        return R.okHasData(MobileCategoryConvert.INSTANCE.convert(list));

    }

}
